<!-- @@master  = ../../../tpl/base.html-->
<!-- @@block  =  head-->
<style media="screen">
.user-invoice{
  display: none;
}
</style>
<!-- @@close-->
<!-- @@block  =  content-->
<section class="panel panel-default">
<header class="panel-heading">
  账户充值
<span class="tools pull-right">
    <a class="fa fa-chevron-down" href="javascript:;"></a>
    <a class="fa fa-times" href="javascript:;"></a>
</span>
</header>
<div class="panel-body">
  <div class="form col-sm-12  col-lg-10">
      <form class="cmxform form-horizontal adminex-form" id="rechargeForm" method="get" action="">
        <div class="form-group">
            <label for="money" class="control-label col-sm-2">充值金额</label>
            <div class="col-sm-6">
              <div class="input-group">
                <input class=" form-control" name="amount" type="number" required/>
                <div class="input-group-addon">元</div>
              </div>
            </div>
        </div>
        <div class="form-group">
            <label for="money" class="control-label col-sm-2">确认金额</label>
            <div class="col-sm-6">
              <div class="input-group">
                <input class=" form-control" id="repeat_amount" type="number" />
                <div class="input-group-addon">元</div>
              </div>
            </div>
        </div>
        <div class="form-group ">
            <label class="control-label col-sm-2">发票类型</label>
            <div class="col-sm-10 minimal-green single-row">
                <div class="radio col-sm-3">
                    <label><input tabindex="3" type="radio"  name="invoice_type" value="0" checked>不开票 </label>
                </div>
                <div class="radio col-sm-3">
                    <label><input tabindex="3" type="radio"  name="invoice_type" value="1">普票 </label>
                </div>
                <div class="radio col-sm-3">
                    <label><input tabindex="3" type="radio"  name="invoice_type" value="2">专票 </label>
                </div>
            </div>
        </div>
        <div class="form-group user-invoice">
            <label for="money" class="control-label col-sm-2">发票抬头</label>
            <div class="col-sm-6">
                <input class=" form-control" name="invoice_title"/>
            </div>
        </div>
        <div class="form-group user-invoice">
            <label for="money" class="control-label col-sm-2">收件人</label>
            <div class="col-sm-6">
                <input class=" form-control" name="invoice_receiver"/>
            </div>
        </div>
        <div class="form-group user-invoice">
            <label for="money" class="control-label col-sm-2">联系电话</label>
            <div class="col-sm-6">
                <input class=" form-control" name="invoice_phone"/>
            </div>
        </div>
        <div class="form-group user-invoice">
            <label for="money" class="control-label col-sm-2">快递地址</label>
            <div class="col-sm-6">
                <input class=" form-control" name="invoice_address"/>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-6">
                <button class="btn btn-primary" type="submit">提交</button>
            </div>
        </div>
      </form>
  </div>

</div>
</section>
<!-- @@close-->
<!-- @@block  =  foot-->
<!--dynamic table-->
<script type="text/javascript">
(function() {
    "use strict";
    $("#rechargeForm").validate({
      messages:{
        amount:"请输入充值金额",
        invoice_title:"请输入付款人/公司"
      },
      submitHandler:function(form){
        if(form.amount.value != $("#repeat_amount").val()){
            mygritter("两次金额输入不一致");
            return;
        }

        var params = myHttp.getFormJson(form);
        params.amount = params.amount * 100;
        $.isLoading({text:"loading"});
        myHttp.postJSON("recharge",params,function(data){
          mygritter("充值成功");
          setTimeout(function(){
            $.isLoading("hide");
            window.location.href = "/user/bill.html#user-bill";
          },300);
        },function(msg){
          $.isLoading("hide");
          mygritter(msg);
        });
      }
    });
    //加载用户信息
    var getChannel = function(){
      $.isLoading({text:"loading"});
      myHttp.getJSON("channel",function(data){
          $.isLoading("hide");
          window.user = data;
          rechargeForm.invoice_title.value = data.company;
          rechargeForm.invoice_receiver.value = data.contacter;
          rechargeForm.invoice_phone.value = data.phone;
          rechargeForm.invoice_address.value = data.address;
      },function(){
        $.isLoading({
          text: "您还未登录,请去登录"
        });
        setTimeout(function() {
          window.location.href = "/login.html";
          $.isLoading("hide");
        }, 1000);
      });
    }
    getChannel();

    $(document).on('keyup keydown change','input[name="invoice_type"]',function(){
      if($(this).val() == 0){
        $(".user-invoice").hide();
      }else{
        $(".user-invoice").show();
      }
    });
})(jQuery);
</script>
<!-- @@close-->
